﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using Database;
using Business;

namespace DT5_Anh09110006_Hung09110044_Vu09110157
{
    public class MyRole:RoleProvider
    {
        TrungTamEntities trungtam = new TrungTamEntities();
        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            string[] roles = { "Giám Đốc", "Kế Toán"};
            return roles;                                  
        }

        public override string[] GetRolesForUser(string username)
        {

            var role = from p in trungtam.NguoiDungs
                       where p.TaiKhoan.Equals(username)
                       select p.NhanVien.ChucVu;
            return role.ToArray();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            var users = from p in trungtam.NguoiDungs
                        where p.NhanVien.ChucVu.Equals(roleName)
                        select p.TaiKhoan;
            return users.ToArray();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            try
            {
                var user = from p in trungtam.NguoiDungs
                           where p.TaiKhoan.Equals(username)
                              && p.NhanVien.ChucVu.Equals(roleName)
                           select p;
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}